package testIntergration;


import static org.junit.Assert.assertEquals;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.PrintStream;
import java.lang.reflect.Method;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import FamilyTherapy.GCWindow;
import FamilyTherapy.Game;
import FamilyTherapy.Player;
import FamilyTherapy.SayActCard;

public class testGame_drawSA {

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}


	
	@Test
	public void testDrawSA() throws Exception {
		int currentPlayerNo = 1;
		boolean ABC=false;
		//int ABC=1;
		
		String result="";
		Player[] p = { new Player("a", 1), new Player("b", 2) };
			
		
		class GCWindowStub extends GCWindow{
			@Override
			public void requestUsingSA(SayActCard currentSA,int currentPlayerNo, Player p[])
			{
		
			}
		}

		String[] e={ 
				"SA1_Say \"I love you\" to parents\n"+
			"Description :SA1_Say \"I love you\" to parents\n",
			"SA2_Help mother to do housework\n"+
			"Description :SA2_Help mother to do housework\n",
			"SA3_Teach brother to do homework\n"+
			"Description :SA3_Teach brother to do homework\n",
			"SA4_Prepare a lunch\n"+
			"Description :SA4_Prepare a lunch\n",
			"SA5_Say \"Thank you to everyone\" \n"+
			"Description :SA5_Say \"Thank you to everyone\" \n"
		};

		String e1="SA1_Say \"I love you\" to parents\n"+
		"Description :SA1_Say \"I love you\" to parents\n";
		String e2="SA2_Help mother to do housework\n"+
		"Description :SA2_Help mother to do housework\n";
		String e3="SA3_Teach brother to do homework\n"+
		"Description :SA3_Teach brother to do homework\n";
		String e4="SA4_Prepare a lunch\n"+
		"Description :SA4_Prepare a lunch\n";
		String e5="SA5_Say \"Thank you to everyone\" \n"+
		"Description :SA5_Say \"Thank you to everyone\" \n";
		
		GCWindow gcWindow= new GCWindowStub ();
		// output
		final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
		System.setOut(new PrintStream(outContent));
	
		Game game = new Game();

		Method drawSaMethod = game.getClass().getDeclaredMethod(
		"drawSA", GCWindow.class, int.class, Player[].class);
		
		drawSaMethod.setAccessible(true);
		
		drawSaMethod.invoke(game, gcWindow,currentPlayerNo,p); 
		//result="SA5_Say \"Thank you to everyone\" \n"+
		//"Description :SA5_Say \"Thank you to everyone\" \n";
		drawSaMethod.setAccessible(false);
		
		result=outContent.toString();
		int hihi=0;
		for(int i=0;i<5;i++){
			if(e[i].equalsIgnoreCase(result)){
				ABC=true;
			}	
		}
		//if(e[0]==result||e[1]==result||e[2]==result||e[3]==result||e[4]==result){
		//	ABC=true;
		//}

		
		
		//System.out.print(outContent.toString());
		
		//assertEquals(e3, outContent.toString());
		//assertEquals(e1, outContent.toString());
		//assertEquals(e2, outContent.toString());
		//assertEquals(e[4], outContent.toString());
		//assertEquals(e4, outContent.toString());
		assertEquals(true,ABC);

	}
	
}

 